//
// File:	aprcfg.h
// Brief:	各table与相关操作定义
//
// History:
// ============================================================================
// 2011-01-17    Finux Chen <finuxchen@gmail.com>    创建
// 2011-02-17    Finux Chen <finuxchen@gmail.com>    添加光量项目相关操作
//
#ifndef _APRCFG_H
#define _APRCFG_H

#include <QString>
#include <QStringList>
#include "../define.h"

typedef ushort citem_t[MAX_ITEM_QTY+40];
typedef bool usechn_t[MAX_CHANNEL_QTY];
typedef int  chnitem_t[MAX_CHANNEL_QTY];

#define MST_HUE 1
#define MST_VL  2
#define MST_DLM 4

class AprCfg
{
public:
	//// 各项目通用查表操作 ////////////////////////////////////////////////
	static bool getParamCodeByName(_IN	const QString	&name,
								   _IN	para_attr_e		attr,
								   _OUT	ushort			&code);

	static bool getNamesByAttr(_IN	para_attr_e attr, 
                               _OUT QStringList &names);


	static bool getParamNameByCode(_IN ushort code, _OUT QString &name);

	static bool getRangesByItem(_IN 	const QString 	&item, 
								_IN		para_attr_e		attr, 
                                _OUT	QStringList		&ranges);
					
	static bool getRangeDetailByName(_IN 	const QString	&range,
									 _IN 	para_attr_e 	attr,
									 _OUT 	double 			&upper,
									 _OUT 	double 			&lower,
									 _OUT 	double 			&step,
									 _OUT 	ushort			&decimals);
								 
	static bool getRangeDetailByCode(_IN	ushort	code,
									 _OUT	double	&upper,
									 _OUT	double	&lower,
									 _OUT	double	&step,
									 _OUT	ushort	&decimals);
									 
	static bool getRangeInfoByCode(_IN	ushort	code, 
								   _OUT QString &unit,
								   _OUT long	&coef);						 

	// last 3 functions are old-style, we should use this one instead!!!
	static const rng_tbl_s *getRangeByCode(ushort code);
	
    static bool getDevIndexByCode(_IN ushort code, _OUT ushort &index);

	static const devtbl_s *getDevTable() { return devTblm; }


	//// 光量相关操作 ///////////////////////////////////////////////////////
	static ushort createHueIndex(_IN	const program_s& program,
								 _OUT	citem_t &citem);
	
	static ushort getHueItems(_IN const program_s& program,
							  _IN const	short* code, 
							  _IN 		bool bFirstItem, 
							  _IN 		bool bCheckBias);

	static bool getHueItemsList(_IN		const program_s& 	program,
								_OUT	QStringList&		items,
							 	_OUT	citem_t&			citem,
							 	_OUT	usechn_t&			usechn,
								_OUT    chnitem_t&			chnitem);

	static bool isHueItem(_IN short itemCode);

	//
	// TODO: 转换device的表示形式
	//

private:
	//
	// 禁止编译器自动生成下列函数的public版本,不需要
	//
	AprCfg() {}
	~AprCfg() {}
	AprCfg(const AprCfg &) {}
    AprCfg &operator=(const AprCfg &);

	
	static bool getBiasMeasModeByItem(_IN	const QString	&item,
									  _IN	para_attr_e		attr,
									  _OUT	char			&mode);

	///// 各项目通用表 //////////////////////////////////////////////////////
	static const prm_tbl_s 	paramTblm[];
	static const rng_tbl_s	rangeTblm[];
	static const devtbl_s	devTblm[];
	static const rng_def_s	rngDefTblm[];

	///// 光量项目相关表 ////////////////////////////////////////////////////
	static const short usemitem[];
	static const short hueitem[];
	static const short vlitem[];
	static const short lmitem[];
};


#endif //_APRCFG_H
